{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "GLC30.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/master/GLC30.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2yE6LcDqyC-y",
        "colab_type": "text"
      },
      "source": [
        "<!--COURSE_INFORMATION-->\n",
        "<img align=\"left\" style=\"padding-right:10px;\" src=\"https://sitejerk.com/images/google-earth-logo-png-5.png\" width=5% >\n",
        "<img align=\"right\" style=\"padding-left:10px;\" src=\"https://colab.research.google.com/img/colab_favicon_256px.png\" width=6% >\n",
        "\n",
        "\n",
        ">> *This notebook is part of the free course [EEwPython](https://colab.research.google.com/github/csaybar/EEwPython/blob/master/index.ipynb); the content is available [on GitHub](https://github.com/csaybar/EEwPython)* and released under the [Apache 2.0 License](https://www.gnu.org/licenses/gpl-3.0.en.html). "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "i_ZzJNDEyEWr",
        "colab_type": "text"
      },
      "source": [
        "<!--NAVIGATION-->\n",
        " < [xXx](cmip5.ipynb) | [Contents](index.ipynb) | [XxX](CNN_demo.ipynb)>\n",
        "\n",
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/master/dnn_demo.ipynb\"><img align=\"left\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\" title=\"Open and Execute in Google Colaboratory\"></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IlR0svs6yLo5",
        "colab_type": "text"
      },
      "source": [
        "<center>\n",
        "<h1>Google Earth Engine with Python </h1>\n",
        "<h2> Download the GLC30 product:  Just available for Peru and Ecuador</h2>\n",
        "</center>\n",
        "\n",
        "```\n",
        "FILE: GLC30.ipynb\n",
        "AUTHOR: Cesar Aybar\n",
        "EMAIL: csaybar@gmail.com\n",
        "ORGANIZATION: n/a \n",
        "MODIFIED BY: n/a\n",
        "CREATION DATE: 8 June 2019\n",
        "LAST MOD DATE: N/A\n",
        "DEPENDENCIES: earthengine-api, geopandas , folium\n",
        "PURPOSE: Simple way for download the GLC30.\n",
        "```\n",
        "\n",
        "\n",
        "Land Cover information is fundamental for environmental change studies, land resource management, sustainable development, and many other societal benefits. In **Google Earth Engine** existing different coarse Land use/cover products (e.g. MCD12Q1-500m) that are not able to capture the most significant human impacts on land systems due to its spatial resolution. Therefore, this short post aims to introduce and explain step by step how to download the [GLC30](https://reader.elsevier.com/reader/sd/pii/S0924271614002275?token=BF89D29031101CDB800927F3DA0DA572A4BBBA74220D9178A24F13A5140E629638CFA580F464F61E1500662B55B90A76) a relative new Global Land Cover product at 30-meter spatial resolution.\n",
        "\n",
        "<center>\n",
        "<img src='http://www.globallandcover.com/home/images/vegas.jpg'>\n",
        "</center>\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YylwGlEWycfT",
        "colab_type": "text"
      },
      "source": [
        "## 1. Installing\n",
        "\n",
        "Before coding do not forget install and load the following packages and remenber that you can communicate with the bash console prepending an ! to the code. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WwXuovxVyee7",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install geopandas #tensorflow 2.0\n",
        "!pip install earthengine-api==0.1.175 #earthengine API"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Q5FS3OHfyiPX",
        "colab_type": "text"
      },
      "source": [
        "## 2. Authentification\n",
        "\n",
        "This tutorial needs interacting with others Google services. For accomplish this task, it's necessary to authenticate (as yourself). The code below shows you how to do it.\n",
        "\n",
        "- **Google Drive**\n",
        "\n",
        "We will use Google Drive for save us results."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GHCiaHRxyfCN",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')  "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Y61sq9LYzJDW",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Earth Engine**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ivdpGRAozSnu",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!earthengine authenticate "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "o3fBkGnKzhHQ",
        "colab_type": "text"
      },
      "source": [
        "## 3. Testing the software setup"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FoJOO1_Ozitx",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Earth Engine Python API\n",
        "import ee\n",
        "ee.Initialize()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YHkxZgcazjb3",
        "colab_type": "code",
        "outputId": "21747be7-dcb6-43c1-9252-0e290109ba39",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 53
        }
      },
      "source": [
        "import folium\n",
        "import geopandas as gpd\n",
        "\n",
        "# Define the URL format used for Earth Engine generated map tiles.\n",
        "EE_TILES = 'https://earthengine.googleapis.com/map/{mapid}/{{z}}/{{x}}/{{y}}?token={token}'\n",
        "\n",
        "print('Folium version: ' + folium.__version__)\n",
        "print('Geopandas version: ' + gpd.__version__)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Folium version: 0.8.3\n",
            "Geopandas version: 0.5.0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WZI5M3JNz1iH",
        "colab_type": "text"
      },
      "source": [
        "## 4. Display either ee.Image or ee.Feature\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MpuPrrjuz7Yn",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def Mapdisplay(center, dicc, Tiles=\"OpensTreetMap\",zoom_start=10):\n",
        "    '''\n",
        "    :param center: Center of the map (Latitude and Longitude).\n",
        "    :param dicc: Earth Engine Geometries or Tiles dictionary\n",
        "    :param Tiles: Mapbox Bright,Mapbox Control Room,Stamen Terrain,Stamen Toner,stamenwatercolor,cartodbpositron.\n",
        "    :zoom_start: Initial zoom level for the map.\n",
        "    :return: A folium.Map object.\n",
        "    '''\n",
        "    mapViz = folium.Map(location=center,tiles=Tiles, zoom_start=zoom_start)\n",
        "    for k,v in dicc.items():\n",
        "      if ee.image.Image in [type(x) for x in v.values()]:\n",
        "        folium.TileLayer(\n",
        "            tiles = EE_TILES.format(**v),\n",
        "            attr  = 'Google Earth Engine',\n",
        "            overlay =True,\n",
        "            name  = k\n",
        "          ).add_to(mapViz)\n",
        "      else:\n",
        "        folium.GeoJson(\n",
        "        data = v,\n",
        "        name = k\n",
        "          ).add_to(mapViz)\n",
        "    mapViz.add_child(folium.LayerControl())\n",
        "    return mapViz"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GWB-rF800qVR",
        "colab_type": "text"
      },
      "source": [
        "## 5. Preparing Geometry Data (Geopandas to EE)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OXzh97q20uUf",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#download the geometry \n",
        "import urllib\n",
        "url = 'https://github.com/csaybar/csaybar.github.io/raw/master/data/provinces.geojson'\n",
        "urllib.request.urlretrieve(url, 'Peru.geojson')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NC_mv63v4lTr",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Reading the file\n",
        "peruprov = gpd.read_file('Peru.geojson')\n",
        "lima = peruprov[peruprov.NOMBRE == 'LIMA'].to_json() # Selecting Lima\n",
        "lima_coords = eval(lima)['features'][0]['geometry']['coordinates'][0] #getting just the coordinates\n",
        "\n",
        "# ee.Geometry -> ee.Feature -> ee.FeatureCollection\n",
        "eeLima = ee.FeatureCollection([ee.Feature(ee.Geometry.Polygon(lima_coords),{'Name':'Lima'})])"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mE3I44jz-PvE",
        "colab_type": "code",
        "outputId": "0e68a7b6-240e-4dbc-e927-21ce3dc63a82",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 741
        }
      },
      "source": [
        "# display the geometry using folium\n",
        "center = eeLima.geometry().centroid().getInfo()['coordinates']\n",
        "center.reverse()\n",
        "\n",
        "fig =eePeru.draw(**{'color': 'FF0000', 'strokeWidth': 5}).getMapId()\n",
        "\n",
        "Mapdisplay(center,{'Lima':fig})"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgID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XJfY29udHJvbF83YjlhYmMzZDZjMGQ0NTM4YmIyNzMzOWVhZDg5MDJlZi5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzMzMDFlMWZkYWY1YjQ2YjdhYjFjZTg2YzhiNjQ1YzI3KTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7f365cebbc50>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 144
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TftBSdw9EaQ8",
        "colab_type": "text"
      },
      "source": [
        "## 6. Reading and clipping the GLC30 dataset"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2JpEWvXNEe9e",
        "colab_type": "code",
        "outputId": "4859396c-33dd-47af-fd96-95f1da5b8234",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 741
        }
      },
      "source": [
        "# Remove 0 and 255 values (no data)\n",
        "def removevalues(img):\n",
        "  value_0 = img.neq(0)\n",
        "  value_255 = img.neq(255)\n",
        "  return img.updateMask(value_0).updateMask(value_255).divide(10).int()\n",
        "\n",
        "# Load the dataset\n",
        "glc30 = ee.ImageCollection('users/csaybar/GLC30PERU')\\\n",
        "          .map(removevalues).max().clip(eeLima)\n",
        "\n",
        "# Define a palette for the distinct land cover classes.\n",
        "glc30Palette = [\n",
        "  'ff02d0', # 1-Cultaved Lands\n",
        "  '147749', # 2-Forest    \n",
        "  'a9d05f', # 3-Grassland  \n",
        "  '3eb370', # 4-Shrublands\n",
        "  '7ecef4', # 5-Wetlands\n",
        "  '00569a', # 6-Water bodies          \n",
        "  '6f6f6f',  # 7-Tundra\n",
        "  '911818', # 8-Artificial Surfaces\n",
        "  'cacaca', # 9-Bareland    \n",
        "  'f9f3c1', # 10-Permanent snow and ice  \n",
        "]\n",
        "vizparams = {'min':1,'max':10,'palette':glc30Palette}\n",
        "Mapdisplay(center,{'glc30':glc30.getMapId(vizparams)},zoom_start=10)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvb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m1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzhjODlmMTEzZThlZDQwOTE5NjRhNjVkYmRmNjllODgzKTsKICAgIAogICAgICAgICAgICB2YXIgbGF5ZXJfY29udHJvbF8yMTQzZDMyZWQwYjM0OTI4YTkzNzhlNmUwZmY4MGY1YiA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogeyAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyXzMwZmQ4M2NmYjZhZjQwOTE5ODc1ZWU2N2RmMWYwYWRiLCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJnbGMzMCIgOiB0aWxlX2xheWVyX2QyMTZlYmE1MTczYTQ2ZDJiYmMwOTVlNWQ5NDNiZjkzLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF8yMTQzZDMyZWQwYjM0OTI4YTkzNzhlNmUwZmY4MGY1Yi5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMjE0M2QzMmVkMGIzNDkyOGE5Mzc4ZTZlMGZmODBmNWIub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF84Yzg5ZjExM2U4ZWQ0MDkxOTY0YTY1ZGJkZjY5ZTg4Myk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7f365cebb208>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 151
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ctaznPkDNeTQ",
        "colab_type": "text"
      },
      "source": [
        "## 6. Export the results of EE to Google Drive"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hIoDvGAGOXjC",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Export the image, specifying scale and region.\n",
        "task = ee.batch.Export.image.toDrive(**{\n",
        "    'image': glc30,\n",
        "    'description': 'GLC30LIMA',\n",
        "    'folder':'GLC30',\n",
        "    'scale': 30,\n",
        "    'region': eeLima.geometry().getInfo()['coordinates']\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "W9pOF-F1ObaG",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import time \n",
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}